<?php
/**
 * redis+mysql冷热数据交互
 * Created by PhpStorm.
 * User: WenQing
 * Date: 2017/7/27
 * Time: 14:41
 */

//addDataFromMysql(rand(1,100000), rand(1,1000000));
addDateFromRedis(rand(1,100000), rand(1,1000000));

/**
 * Percentage of the requests served within a certain time (ms)
50%  27540
66%  29466
75%  30292
80%  30416
90%  30847
95%  30913
98%  30943
99%  31004
100%  32006 (longest request)
 * @param $username
 * @param $password
 * create WenQing
 */
function addDataFromMysql($username, $password)
{
    $con = mysqli_connect('127.0.0.1', 'root', 'zroot');
    mysqli_select_db($con, 'test');
    mysqli_query($con,"insert into customers (phone, password) values ($username, $password)");
    mysqli_close($con);
}

function addDateFromRedis($username, $password)
{
    $redis = new Redis();
    $redis->connect('127.0.0.1', 6379);
    $redis->incr('id');
    $id = $redis->get('id');
    $redis->hMset('customer'.$id,[
        'username' => $username,
        'password' => $password
    ]);
}